

% necessary to get rid of non-valid linescans obtained from
% detectVesselCenters; inputs are the output from detectVesselCenters and
% the endpoints generated by linescansFromCenters
function valids = cullEndpoints(ep1,ep2,edgeim)

valids = zeros(size(ep1,1),1);
for n = 1:size(ep1,1)
    x = [ep1(n,1),ep2(n,1)];
    y = [ep1(n,2),ep2(n,2)];
    cur = checkLinescan(x,y,edgeim);
    if cur
        valids(n) = 1;
    end
end
valids = find(valids==1);


function r = checkLinescan(x,y,edgeim)

linescan = improfile(edgeim,x,y);
if sum(linescan(1:(round(length(linescan)/2)))) > .5 && sum(linescan((round(length(linescan)/2):end))) > .5 && ...
        sum(linescan(1:(round(length(linescan)/2)))) < 2.5 && sum(linescan((round(length(linescan)/2):end))) < 2.5
    r = 1;
else
    r = 0;
end

return;